home *** CD-ROM | disk | FTP | other *** search
- #include "global.h"
- #include "mbuf.h"
- #include "amiga/asy.h"
- #include "iface.h"
- #include "kiss.h"
- #include "slip.h"
- #include "ax25.h"
-
- int kiss_stop __ARGS((struct iface *iface));
-
- /* Send raw data packet on KISS TNC */
- int
- kiss_raw(iface,data)
- struct iface *iface;
- struct mbuf *data;
- {
- register struct mbuf *bp;
-
- /* Put type field for KISS TNC on front */
- if((bp = pushdown(data,1)) == NULLBUF){
- free_p(data);
- return -1;
- }
- bp->data[0] = KISS_DATA;
- bp->data[0] |= (iface->port << 4);
-
- iface->rawsndcnt++;
- iface->lastsent = Clock;
-
- /* slip_raw also increments sndrawcnt */
- slip_raw(Slip[iface->xdev].iface,bp);
- return 0;
- }
-
- /* Process incoming KISS TNC frame */
- void
- kiss_recv(iface,bp)
- struct iface *iface;
- struct mbuf *bp;
- {
- char kisstype;
- struct iface *kissif;
- int port;
-
- kisstype = pullchar(&bp);
- port = kisstype >> 4;
-
- if((kissif = Slip[iface->xdev].kiss[port]) == NULLIF){
- free_p(bp);
- return;
- }
-
- switch(kisstype & 0xf){
- case KISS_DATA:
- ax_recv(kissif,bp);
- break;
- default:
- free_p(bp);
- break;
- }
- }
-
- /* Perform device control on KISS TNC by sending control messages */
- int
- kiss_ioctl(iface,argc,argv)
- struct iface *iface;
- int argc;
- char *argv[];
- {
- struct mbuf *hbp;
- int i;
- char *cp;
-
- if(argc < 1){
- tprintf("Data field missing\n");
- return 1;
- }
- /* Allocate space for arg bytes */
- if((hbp = ambufw((int16)argc)) == NULLBUF){
- free_p(hbp);
- return 0;
- }
- hbp->cnt = argc;
- hbp->next = NULLBUF;
- for(i=0,cp = hbp->data;i < argc;)
- *cp++ = atoi(argv[i++]);
-
- if(hbp->data[0] != (char) KISS_RETURN)
- hbp->data[0] |= (iface->port << 4);
-
- iface->rawsndcnt++;
- iface->lastsent = Clock;
-
- slip_raw(Slip[iface->xdev].iface,hbp); /* Even more "raw" than kiss_raw */
- return 0;
- }
-
- int
- kiss_stop(iface)
- struct iface *iface;
- {
- Slip[iface->xdev].kiss[iface->port] = NULLIF;
- return 0;
- }
-
- /* Attach a kiss interface to an existing asy interface in the system
- * argv[0]: hardware type, must be "kiss"
- * argv[1]: master interface, e.g., "ax4"
- * argv[2]: kiss port, e.g., "4"
- * argv[3]: interface label, e.g., "ax0"
- * argv[4]: maximum transmission unit, bytes
- */
- int
- kiss_attach(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- struct iface *if_asy, *if_kiss;
- int port;
-
- if((if_asy = if_lookup(argv[1])) == NULLIF){
- tprintf("Interface %s does not exist\n",argv[1]);
- return -1;
- }
-
- if(if_lookup(argv[3]) != NULLIF){
- tprintf("Interface %s already exists\n",argv[4]);
- return -1;
- }
-
- if((port = atoi(argv[2])) == 0){
- tprintf("Port 0 automatically assigned to interface %s\n",argv[1]);
- return -1;
- }
-
- if(port < 1 || port > 15){
- tprintf("Ports 1 to 15 only\n");
- return -1;
- }
-
- if(Slip[if_asy->xdev].kiss[port] != NULLIF){
- tprintf("Port %d already allocated on interface %s\n", port, argv[1]);
- return -1;
- }
- /* Create interface structure and fill in details */
- if_kiss = (struct iface *)callocw(1,sizeof(struct iface));
- if_kiss->addr = if_asy->addr;
- if_kiss->name = strdup(argv[3]);
-
- if(argc >= 5){
- if_kiss->mtu = atoi(argv[4]);
- } else {
- if_kiss->mtu = if_asy->mtu;
- }
-
- if_kiss->dev = if_asy->dev;
- if_kiss->stop = kiss_stop;
- setencap(if_kiss,"AX25");
- if_kiss->ioctl = kiss_ioctl;
- if_kiss->raw = kiss_raw;
- if(if_kiss->hwaddr == NULLCHAR)
- if_kiss->hwaddr = mallocw(AXALEN);
- memcpy(if_kiss->hwaddr,Mycall,AXALEN);
- if_kiss->xdev = if_asy->xdev;
- if_kiss->next = Ifaces;
- Ifaces = if_kiss;
- if_kiss->port = port;
- Slip[if_kiss->xdev].kiss[if_kiss->port] = if_kiss;
- return 0;
- }
-
-